package xx.pro;

import sun.nio.ch.ThreadPool;

import java.util.Date;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor executorService = new ThreadPoolExecutor(2,
                10,
                0, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(2));

        for (int i = 0; i < 10; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Date date = new Date();
                        System.out.println("线程：" + Thread.currentThread().getName() + "Time is ：" + date);
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                    }
                }
            });
            System.out.println("等待队列中现在有" + executorService.getQueue().size() + "个任务");
            Thread.sleep(500);
        }
    }
}
